home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / METAFILE.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  335 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.6  $
  6. //
  7. // Definition of TMetafilePict, a MetaFile wrapper class
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_METAFILE_H)
  10. #define OWL_METAFILE_H
  11.  
  12. #if !defined(OWL_GDIBASE_H)
  13. # include <owl/gdibase.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. // Generic definitions/compiler options (eg. alignment) preceeding the 
  21. // definition of classes
  22. #include <services/preclass.h>
  23.  
  24. class _OWLCLASS TClipboard;
  25. class _OWLCLASS TDC;
  26.  
  27. //
  28. // METAFILEHEADER is used generally to create placeable metafiles
  29. // (Originally created by Aldus; described by Microsoft in the
  30. // Win 3.1 SDK; not declared in any Microsoft headers.)
  31. //
  32. // The placeable metafile header was originally a 16-bit structure, but it
  33. // contains two fields of types that are normally polymorphic between
  34. // 16 and 32 bits: RECT and HANDLE.  RECT16 is a non-polymorphic 16-bit
  35. // RECT, needed to preserve alignment when reading mf headers into
  36. // 32-bit programs.
  37. //
  38.  
  39. // Users may have defined METAFILEHEADER for themselves.
  40. //
  41. #if !defined(METAFILEHEADER)
  42. typedef struct {
  43.   int16 left;
  44.   int16 top;
  45.   int16 right;
  46.   int16 bottom;
  47. } RECT16;
  48.  
  49. typedef struct {
  50.     DWORD   key;            // identifies file type
  51.     
  52.     // hmf is defined as HANDLE, but in Win16 that's an unsigned int
  53.     WORD    hmf;            // unused (0)
  54.     
  55.     RECT16  bbox;           // bounding rectangle
  56.     WORD    inch;           // units per inch
  57.     DWORD   reserved;       // unused (0)
  58.     WORD    checksum;       // XOR of previous fields
  59. } METAFILEHEADER;
  60. #endif
  61.  
  62. //
  63. // class TMetafilePict
  64. // ~~~~~ ~~~~~~~~~~~~~
  65. // A class that wraps a windows metafile that can be played into a DC, or
  66. // put on the clipboard, etc.
  67. //
  68. class _OWLCLASS TMetaFilePict : private TGdiBase {
  69.   public:
  70.     TMetaFilePict(HMETAFILE handle, TAutoDelete autoDelete);
  71.     TMetaFilePict(const TClipboard& clipboard);
  72.     TMetaFilePict(const char* filename);
  73. #if defined(BI_PLAT_WIN32)
  74.     TMetaFilePict(uint size, void far* data);
  75. #else
  76.     TMetaFilePict(HGLOBAL data);
  77. #endif
  78.     TMetaFilePict(const TMetaFilePict&, const char far* fileName = 0);
  79.    ~TMetaFilePict();
  80.  
  81.     operator    HMETAFILE() const;
  82.  
  83. #if defined(BI_PLAT_WIN32)
  84.     uint32      GetMetaFileBitsEx(uint size, void* data);
  85. #else
  86.     HANDLE      GetMetaFileBits();
  87. #endif
  88.  
  89.     // Play this metafile onto a dc
  90.     //
  91.     TSize     CalcPlaySize(TDC& dc, const TSize& defSize) const;
  92.     bool      PlayOnto(TDC& dc, const TSize& defSize) const;
  93.  
  94.     // Put this MetaFilePict onto the clipboard
  95.     //
  96.     void      ToClipboard(TClipboard& clipboard,
  97.                           uint mapMode = MM_ANISOTROPIC,
  98.                           const TSize& extent=TSize(0,0));
  99.  
  100.     // Retrieve attributes of this metafile
  101.     //
  102.     uint      MappingMode() const;
  103.     int       Width() const;
  104.     int       Height() const;
  105.     TSize     Size() const;
  106.  
  107.     // Set attributes of this metafile
  108.     //
  109.     void      SetMappingMode(uint mm);
  110.     void      SetSize(const TSize& size);
  111.  
  112.     // Methods for placeable metafiles
  113.     //
  114.     bool IsPlaceable();
  115.     bool GetPlaceableHeader(METAFILEHEADER& header);
  116.     void SetPlaceableHeader(TRect& bounds, uint16 unitsPerInch);
  117.  
  118.  
  119.   protected:
  120.     uint16 CalcHeaderChecksum(const METAFILEHEADER& mfHeader);
  121.  
  122.   protected_data:
  123.     int    Mm;        // Mapping mode
  124.     TSize  Extent;
  125.     bool Placeable;
  126.     METAFILEHEADER MFHeader;
  127.     static const uint32 MFHeaderKey;
  128.  
  129.   private:
  130.     // Hidden to prevent accidental copying or assignment
  131.     //
  132.     TMetaFilePict& operator=(const TMetaFilePict&);
  133. };
  134.  
  135. #if defined(BI_PLAT_WIN32)
  136. //
  137. // class TEnhMetaFilePict
  138. // ~~~~~ ~~~~~~~~~~~~~~~~
  139. // A class that encapsulates the enhanced metafile.
  140. //
  141. class _OWLCLASS TEnhMetaFilePict : private TGdiBase {
  142.   public:
  143.     TEnhMetaFilePict(HENHMETAFILE handle, TAutoDelete autoDelete);
  144.     TEnhMetaFilePict(const char* filename);
  145.     TEnhMetaFilePict(const TEnhMetaFilePict& metafilepict, const char far* filename);
  146.     TEnhMetaFilePict(uint bytes, const void* buffer);
  147.    ~TEnhMetaFilePict();
  148.  
  149.     operator HENHMETAFILE() const;
  150.  
  151.     // Play this metafile onto a dc
  152.     //
  153.     bool PlayOnto(TDC& dc, const TRect* rect) const;
  154.  
  155.     // Retrieve attributes of this metafile
  156.     //
  157.     uint GetBits(uint bytes, void* buffer);
  158.     uint GetDescription(uint bytes, void* buffer);
  159.     uint GetHeader(uint bytes, ENHMETAHEADER* record);
  160.     uint GetPaletteEntries(uint count, PALETTEENTRY* entries);
  161.  
  162.   private:
  163.     // Hidden to prevent accidental copying or assignment
  164.     //
  165.     TEnhMetaFilePict& operator=(const TEnhMetaFilePict&);
  166. };
  167. #endif
  168.  
  169. // Generic definitions/compiler options (eg. alignment) following the 
  170. // definition of classes
  171. #include <services/posclass.h>
  172.  
  173. #if defined(BI_NAMESPACE)
  174. } // namespace OWL
  175. #endif
  176.  
  177. //----------------------------------------------------------------------------
  178. // Inline implementations
  179. //
  180.  
  181. //
  182. // Inserts the metafile picture onto the clipboard.
  183. //
  184. inline TClipboard& operator <<(TClipboard& clipboard, TMetaFilePict& mfp) {
  185.   mfp.ToClipboard(clipboard);
  186.   return clipboard;
  187. }
  188.  
  189. //
  190. // Return the associated handle for the metafile object.
  191. //
  192. inline TMetaFilePict::operator HMETAFILE() const {
  193.   return HMETAFILE(Handle);
  194. }
  195.  
  196. //
  197. //
  198. //
  199. inline bool
  200. TMetaFilePict::IsPlaceable() {
  201.   return Placeable;
  202. }
  203.  
  204. //
  205. //
  206. //
  207. inline bool
  208. TMetaFilePict::GetPlaceableHeader(METAFILEHEADER& header) {
  209.   if (IsPlaceable()) {
  210.     header = MFHeader;
  211.     return true;
  212.   }
  213.   else
  214.     return false;
  215. }
  216.  
  217. //
  218. //  Warning: values in the bounds rectangle will be cast to unsigned
  219. //  int values.
  220. //
  221. inline void
  222. TMetaFilePict::SetPlaceableHeader(TRect& bounds, uint16 unitsPerInch) {
  223.   MFHeader.key         = MFHeaderKey;
  224.   MFHeader.hmf         = (WORD)Handle;
  225.   MFHeader.bbox.left   = (int16)bounds.left;
  226.   MFHeader.bbox.top    = (int16)bounds.top;
  227.   MFHeader.bbox.right  = (int16)bounds.right;
  228.   MFHeader.bbox.bottom = (int16)bounds.bottom;
  229.   MFHeader.inch        = unitsPerInch;
  230.   MFHeader.reserved    = 0;
  231.   MFHeader.checksum    = CalcHeaderChecksum(MFHeader);
  232.   Placeable = true;
  233. }
  234.  
  235. #if !defined(BI_PLAT_WIN32)
  236. //
  237. // Retrieve the bits for the metafile.
  238. //
  239. inline HANDLE TMetaFilePict::GetMetaFileBits() {
  240.   return ::GetMetaFileBits(HMETAFILE(Handle));
  241. }
  242. #endif
  243.  
  244. //
  245. // Return the mapping mode of the metafile.
  246. //
  247. inline uint
  248. TMetaFilePict::MappingMode() const {
  249.   return Mm;
  250. }
  251.  
  252. //
  253. // Return the width of the metafile.
  254. //
  255. inline int
  256. TMetaFilePict::Width() const {
  257.   return Extent.cx;
  258. }
  259.  
  260. //
  261. // Return the height of the metafile.
  262. //
  263. inline int
  264. TMetaFilePict::Height() const {
  265.   return Extent.cy;
  266. }
  267.  
  268. //
  269. // Return the size of the metafile.
  270. //
  271. inline TSize
  272. TMetaFilePict::Size() const {
  273.   return Extent;
  274. }
  275.  
  276. //
  277. // Set the mapping mode for the metafile.
  278. //
  279. inline void
  280. TMetaFilePict::SetMappingMode(uint mm) {
  281.   Mm = mm;
  282. }
  283.  
  284. //
  285. // Set the size of the metafile.
  286. //
  287. inline void
  288. TMetaFilePict::SetSize(const TSize& size) {
  289.   Extent = size;
  290. }
  291.  
  292. #if defined(BI_PLAT_WIN32)
  293. //
  294. // Return the associated handle of the enhanced metafile.
  295. //
  296. inline TEnhMetaFilePict::operator HENHMETAFILE() const {
  297.   return HENHMETAFILE(Handle);
  298. }
  299.  
  300. //
  301. // Return the bits of the metafile.
  302. //
  303. inline uint
  304. TEnhMetaFilePict::GetBits(uint bytes, void* buffer) {
  305.   return ::GetEnhMetaFileBits(*this, bytes, (BYTE*)buffer);
  306. }
  307.  
  308. //
  309. // Retrieve the description of this enhanced metafile.
  310. //
  311. inline uint
  312. TEnhMetaFilePict::GetDescription(uint bytes, void* buffer) {
  313.   return ::GetEnhMetaFileDescription(*this, bytes, (LPTSTR)buffer);
  314. }
  315.  
  316. //
  317. // Retrieve the header information for the enhanced metafile.
  318. //
  319. inline uint
  320. TEnhMetaFilePict::GetHeader(uint bytes, ENHMETAHEADER* record) {
  321.   return ::GetEnhMetaFileHeader(*this, bytes, record);
  322. }
  323.  
  324. //
  325. // Retrieve the palette entries of the enhanced metafile.
  326. //
  327. inline uint
  328. TEnhMetaFilePict::GetPaletteEntries(uint count, PALETTEENTRY* entries) {
  329.   return ::GetEnhMetaFilePaletteEntries(*this, count, entries);
  330. }
  331.  
  332. #endif  // BI_PLAT_WIN32
  333.  
  334. #endif  // OWL_METAFILE_H
  335.